#!/bin/bash

firstFile="$1"
numOfFiles="$2"
tempFileName=$(echo "$firstFile" | sed 's/....$//g')
outputFileName="$tempFileName"

i=1

while [ $i -le $numOfFiles ]
do
	case "$i" in
		[0-9]		)	tempFileName=$(echo "${outputFileName}.00$i");;
		[1-9][0-9]	)	tempFileName=$(echo "${outputFileName}.0$i");;
		[1-9][0-9][0-9] )	tempFileName=$(echo "$outputFileName.$i");;

	esac

	echo "$tempFileName" >> fileList

	cat $tempFileName >> $outputFileName
	i=$(($i + 1))
done

for i in $(cat fileList)
do
	rm -f "$i"
done

rm -f fileList
